<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input clearable style="width: 240px" v-model="queryParams.search.keyword" placeholder="请输入模块标题查询"
          clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="[]"
            >新增</el-button>
          </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="[]">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getDataList" :columns="columns"></right-toolbar>
    </el-row>
    <el-table :data="dataList" v-loading="loading" @selection-change="handleSelectionChange" style="width: 100%;">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="title" label="模块标题" align="center" v-if="columns[0].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="businessType" label="业务类型" align="center" v-if="columns[1].visible"
        :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.businessType==0" type="success">其他</el-tag>
          <el-tag v-else-if="scope.row.businessType==1" type="success">新增</el-tag>
          <el-tag v-else-if="scope.row.businessType==2" type="success">修改</el-tag>
          <el-tag v-else-if="scope.row.businessType==3" type="danger">删除</el-tag>
          <el-tag v-else type="danger">登陆成功</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="method" label="方法名称" align="center" v-if="columns[2].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="requestMethod" label="请求方式" align="center" v-if="columns[3].visible"
        :show-overflow-tooltip="true" />
      <!-- <el-table-column prop="operType" label="操作类别" align="center" v-if="columns[4].visible" :show-overflow-tooltip="true" >
      <template slot-scope="scope">
        <el-tag v-if="scope.row.operType==0" type="success">其他</el-tag>
        <el-tag v-else-if="scope.row.operType==1" type="success">后台用户</el-tag>
        <el-tag v-else-if="scope.row.operType==2" type="success">手机端用户</el-tag>
        <el-tag v-else type="danger">登陆成功</el-tag>
      </template>
    </el-table-column> -->
      <el-table-column prop="operName" label="操作人员" align="center" v-if="columns[5].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="operUrl" label="请求URL" align="center" v-if="columns[6].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="operIp" label="主机地址" align="center" v-if="columns[7].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="operLocation" label="操作地点" align="center" v-if="columns[8].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="operParam" label="请求参数" align="center" v-if="columns[9].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="operResult" label="返回参数" align="center" v-if="columns[10].visible"
        :show-overflow-tooltip="true" />
      <el-table-column prop="status" label="操作状态" align="center" v-if="columns[11].visible"
        :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status==0" type="success">操作成功</el-tag>
          <el-tag v-else type="danger">操作失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="errMsg" label="错误消息" align="center" v-if="columns[12].visible"
        :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="[]" >修改</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['monitor:operlog:list']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getDataList" />
    <!-- 弹窗, 新增 / 修改 -->
    <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
  </div>
</template>
<script>
  import {
    page,
    deleteById,
    addOrUpdate
  } from "@/api/system/sysoperlog";
  // import AddOrUpdate from './addOrUpdate'
  export default {
    data() {
      return {
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        // 总条数
        total: 0,
        //表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 表单参数
        // 显示搜索条件
        showSearch: true,
        form: {},
        // 日期范围
        dateRange: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          search: {

          }
        },
        columns: [{
            key: 0,
            label: '模块标题',
            visible: true
          },
          {
            key: 1,
            label: '业务类型',
            visible: true
          },
          {
            key: 2,
            label: '方法名称',
            visible: true
          },
          {
            key: 3,
            label: '请求方式',
            visible: true
          },
          {
            key: 4,
            label: '操作类别',
            visible: true
          },
          {
            key: 5,
            label: '操作人员',
            visible: true
          },
          {
            key: 6,
            label: '请求URL',
            visible: true
          },
          {
            key: 7,
            label: '主机地址',
            visible: true
          },
          {
            key: 8,
            label: '操作地点',
            visible: true
          },
          {
            key: 9,
            label: '请求参数',
            visible: true
          },
          {
            key: 10,
            label: '返回参数',
            visible: true
          },
          {
            key: 11,
            label: '操作状态',
            visible: true
          },
          {
            key: 12,
            label: '错误消息',
            visible: true
          }
        ],
        dataList: [],
        rules: {},
        addOrUpdateVisible: false
      }
    },
    components: {
      // AddOrUpdate
    },
    created() {
      this.getDataList();
      this.initPage();
    },
    methods: {
      initPage() {

      },
      // 获取数据列表
      getDataList() {
        this.loading = true;
        page(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.dataList = response.data.list;
          this.total = parseInt(response.data.total);
          this.loading = false;
        }).catch(res => {
          this.loading = false
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getDataList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.addOrUpdateVisible = true;
        this.title = "添加";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init({})
        })
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.addOrUpdateVisible = true;
        this.title = "修改";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(row)
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('确定要删除选中的数据项？').then(function() {
          return deleteById(ids);
        }).then(() => {
          this.getDataList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          search: {

          }
        };
        this.getDataList()
      }
    }
  }
</script>
